<?php
/**
 * Created by PhpStorm.
 * User: liuxiaojie
 * Date: 2019-05-15
 * Time: 16:58
 */

namespace app\ops\controller;

class Comcategory extends Base
{

    function index()
    {
        $list = db('category')->select();

        $this->assign('list', $list);
        return $this->fetch();
    }

    function add()
    {
        $post = request()->post();
        if($post)
        {
            unset($post['image']);
            if($post['category_id'])
            {
                db('category')->update($post);
            }else{
                unset($post['category_id']);
                db('category')->insert($post);
            }

        }else{
            return $this->fetch();
        }

        return success([]);
    }

    function edit($id)
    {
        $data = db('category')->where(['category_id'=> $id])->find();
        $this->assign('data', $data);
        return $this->fetch('add');
    }


}